<template>
  <div>
    <search></search>
    <div v-show="shows">
      <van-swipe-cell v-for="(item, index) in myorder" :key="index">
        <van-card
          num="1"
          :price="item.price"
          :desc="item.address"
          :title="item.title"
          class="goods-card"
          :thumb="item.image"
        />
        <div class="myinfos">
          <span>{{ item.name }}</span>
          <span class="fukuan">已付款</span>
          <span>{{ item.iphone }}</span>
        </div>
        <template #right>
          <van-button
            square
            text="删除"
            type="danger"
            class="delete-button"
            @click="dele(item.id)"
          />
        </template>
      </van-swipe-cell>
    </div>
    <div v-show="!shows" class="order-my">
      <p>暂无订单</p>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
import session from '../../http/session'
import search from '../../commonality/navHearder.vue'
export default {
  name: "WorkspaceJsonMyorder",

  data() {
    return {
        myorder:[],
        shows:true,
        uname:''
    };
  },
  components:{
      search
  },

  mounted() {
      
  },
  created(){
      session().then(res=>{
        //   console.log(res.data.data[0].uname);
        this.uname = res.data.data[0].uname
          this.$http.get('/collectInfoShow',{
              params:{
                  username:res.data.data[0].uname
              }
          }).then(result=>{
              if(result.data.data.length==0){
                  this.shows = false
              }else{
                  this.shows = true
                  this.myorder = result.data.data
                  console.log(result.data.data);
              }
          })
      })
  },

  methods: {
      dele(id){
          this.$http.post('/deleteCollect',{
              username:this.uname,
              id:id
          }).then(res=>{
              Toast.success('删除成功');
              history.go(0)
          })
        //  console.log(123);
      },
  },
};
</script>

<style lang="scss" scoped>
.goods-card {
  margin: 0;
  background-color: white;
}

.delete-button {
  height: 100%;
}
.myinfos {
  background: #fff;
  margin-bottom: 10px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
}
.fukuan {
  font-size: 12px;
  color: #ff8700;
}
.order-my {
  text-align: center;
  color: rgb(75, 75, 75);
  font-weight: bold;
  font-size: 18px;
}
</style>